package day0516.interfaceDemo;

import java.util.Objects;

public class Student {
    public boolean equals(Object o) {
        if (this == o) {
            System.out.println("this和o地址相同，所以是同一个对象");
            return true;//表示this对象和o对象是同一个对象
        }
        if (o == null ||  ! (o instanceof Student)){
            System.out.println("this和o不是同一个类型，不相等");
            return false;//表示this对象和o对象是同一个对象
        }
        Student student = (Student) o;
        //return Objects.equals(name, student.name);
        if(name.equals(student.name) && idCard.equals(student.idCard)){
            System.out.println("this和o的属性相等，所以相等");
            return true;
        }else{
            System.out.println("this和o的属性不相等，所以不相等");
            return false;
        }
    }
    public static void main(String[] args) {
        Student s1    =    new Student();
        Student s2     =   s1;
        System.out.println(s1   .equals(  s2) );  //比较两个int数值是否相等
    }

    private String name;//属性私有化
    private String idCard;//身份证号

    public String getIdCard() {
        return idCard;
    }

    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }

    public Student() {
    }

    public Student(String name) {
        this.name = name;
    }

    public void setName(String name){
        this.name=name;//给成员变量name赋值//方法公开化
    }
    public String getName(){//返回本类name成员变量的值
        return name;
    }






    public int hashCode() {
        return Objects.hash(name);
    }
}
